//
//  HttpRequest.m
//  Safflower
//
//  Created by 袁亮 on 2016/11/25.
//  Copyright © 2016年 Migic_Z. All rights reserved.
//

#import "HttpRequest.h"

@implementation HttpRequest

+(void)GETRequest:(NSString *)requestUrl
       WithParams:(NSDictionary *)params
      WithSuccess:(void(^)(id responseOjbect))success
         WithFail:(void(^)(NSError *error))fail
{
    AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
    
    session.responseSerializer.acceptableContentTypes = \
    [session.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
    
    [session GET:requestUrl parameters:params progress:nil success:^(NSURLSessionDataTask *task, id responseObject){
        if (success) {
            success(responseObject);
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error){
        if (fail) {
            fail(error);
        }
    }];
    
}


+(void)POSTRequest:(NSString *)requestUrl
        WithParams:(NSDictionary *)params
       WithSuccess:(void(^)(id responseOjbect))success
          WithFail:(void(^)(NSError *error))fail
{
    AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
    
    session.responseSerializer.acceptableContentTypes = \
    [session.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
    
    [session POST:requestUrl parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        if (success) {
            success(responseObject);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (fail) {
            fail(error);
        }
    }];
    
}




@end
